package kr.hkit.androidcomplete01;

import kr.hkit.androidcomplete01.ch04.Ch04Main;
import kr.hkit.androidcomplete01.ch05.Ch05Main;
import kr.hkit.androidcomplete01.ch06.Ch06Main;
import kr.hkit.androidcomplete01.ch07.Ch07Main;
import kr.hkit.androidcomplete01.ch08.Ch08Main;
import kr.hkit.androidcomplete01.ch09.Ch09Main;
import kr.hkit.androidcomplete01.ch11.Ch11Main;
import kr.hkit.androidcomplete01.ch12.Ch12Main;
import kr.hkit.androidcomplete01.ch13.Ch13Main;
import kr.hkit.androidcomplete01.ch14.Ch14Main;
import kr.hkit.androidcomplete01.ch15.Ch15Main;
import kr.hkit.androidcomplete01.ch17.Ch17Main;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ListActivity {

	private String[] lists;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_main);

		lists = getResources().getStringArray(R.array.main_list);

		// for (String str : lists) {
		// Log.d("lists", str);
		// }

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, lists);
		setListAdapter(adapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		// l = 리스트 뷰 전체, v = 각각의 리스트 하나하나 position = v의 인덱스 번호
		// String text = "View v = " + v.toString() + ": position = " + position
		// + ", id = " + id;
		// Toast.makeText(this, text, Toast.LENGTH_LONG).show();
		Intent intent = null;

		switch (position) {
		case 0:
			intent = new Intent(this, Ch04Main.class);
			break;
		case 1:
			intent = new Intent(this, Ch05Main.class);
			break;
		case 2:
			intent = new Intent(this, Ch06Main.class);
			break;
		case 3:
			intent = new Intent(this, Ch07Main.class);
			break;
		case 4:
			intent = new Intent(this, Ch08Main.class);
			break;
		case 5:
			intent = new Intent(this, Ch09Main.class);
			break;
		case 6:
			intent = new Intent(this, Ch11Main.class);
			break;
		case 7:
			intent = new Intent(this, Ch12Main.class);
			break;
		case 8:
			intent = new Intent(this, Ch13Main.class);
			break;
		case 9:
			intent = new Intent(this, Ch14Main.class);
			break;
		case 10:
			intent = new Intent(this, Ch15Main.class);
			break;
		case 11:
			intent = new Intent(this, Ch17Main.class);
			break;
		default:
			Toast.makeText(this, "없죵", Toast.LENGTH_LONG).show();
		}
		startActivity(intent);
	}
}
